package pl.s7n.paint.commands;

import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.Raster;

import pl.s7n.paint.utils.FloodFill;

public class FloodFillStrokeCmd extends AbstractStrokeCmd {

  BufferedImage image;
  Raster        oldImage;
  Raster        newImage;

  @Override
  public void draw(Graphics2D g) {
    super.draw(g);
    if (image != null) {
      FloodFill floodFill = new FloodFill(oldImage);
      floodFill.fill(start.x, start.y, tool.getColor());
      BufferedImage temp = floodFill.getImage();
      g.drawRenderedImage(temp, new AffineTransform());
    }
  }

  @Override
  public String toString() {
    return "fill";
  }

  public void setCurrentImageRef(BufferedImage image) {
    this.image = image;
    this.oldImage = image.getData();
  }
}
